﻿using System;
using System.Collections.Generic;
using System.Data;
using DAL;
using Entities;

namespace BLL
{
    public class BLL_News
    {
        private DAL_News dal_News = new DAL_News();

        public DataTable Get_News_All()
        {
            return dal_News.Get_News_All();
        }

        public DataTable Get_HotNews()
        {
            return dal_News.Get_HotNews();
        }

        public DataTable Get_News_Top()
        {
            return dal_News.Get_NewsTop();
        }

        public DataTable Get_News_ByID(int p_news_id)
        {
            return dal_News.Get_News_ByID(p_news_id);
        }

        public DataSet Get_NewsDetail(int p_group_id, int p_news_id)
        {
            return dal_News.Get_NewsDetail(p_group_id, p_news_id);
        }

        public DataSet Get_NewsByGroupID(int p_group_id)
        {
            return dal_News.Get_NewsByGroupID(p_group_id);
        }

        public List<News> Lst_News(DataTable pdt)
        {
            List<News> lstReturn = new List<News>();
            if (pdt != null && pdt.Rows.Count > 0)
            {
                foreach (DataRow dr in pdt.Rows)
                {
                    News news = new News();
                    news.NEWS_ID = Convert.ToInt32(dr["News_id"]);
                    news.TITLE = Convert.ToString(dr["Title"]);
                    news.CONTENT_DESC = Convert.ToString(dr["Content_desc"]);
                    news.CONTENT_DETAIL = Convert.ToString(dr["Content_detail"]);
                    news.ISHOTNEWS = Convert.ToString(dr["IsHotnews"]);
                    news.GROUP_ID = Convert.ToInt32(dr["Group_id"]);
                    news.USER_ID = Convert.ToInt32(dr["User_id"]);
                    news.CREATE_DATE = (dr["Create_date"] == DBNull.Value ? DateTime.MinValue : Convert.ToDateTime(dr["Create_date"]));
                    news.UPDATE_USER_ID = dr["Update_User_id"] == DBNull.Value ? 0 : Convert.ToInt32(dr["Update_User_id"]);
                    news.UPDATE_DATE = dr["Update_date"] == DBNull.Value ? DateTime.MinValue : Convert.ToDateTime(dr["Update_date"]);
                    news.IMAGE_DATA = dr["Image_data"] == DBNull.Value ? null : (byte[])(dr["Image_data"]);
                    lstReturn.Add(news);
                }
            }
            return lstReturn;
        }

        public Int32 InsertNews(News pNews)
        {
            return dal_News.InsertNews(pNews);
        }

        public bool UpdateNews(News pNews)
        {
            return dal_News.UpdateNews(pNews);
        }

        public bool UpdateNewsNotImage(News pNews)
        {
            return dal_News.UpdateNewsNotImage(pNews);
        }

        public bool DeleteNews(Int32 p_news_id)
        {
            return dal_News.DeleteNews(p_news_id);
        }
    }
}
